#!/usr/bin/env python
#encoding=utf8
"""
@描述：消息的消费者，这里用来处理reids队列中的ip
@作者：范红星
@日期：2014年11月20 星期四
"""

import redis
import urllib
import time

if __name__ == "__main__":
	
	client = redis.StrictRedis(host="xp-51",port=6379,db=0)
	ip = client.lpop("ip")

	while True:
		if ip is None:
			time.sleep(1)
			ip = client.lpop("ip")
			continue
		url = "http://ip.sce.sohu.com/ipservice?ip=" + str(ip)
		try:
			socket = urllib.urlopen(url)
			result = socket.read().strip()
			print("%s\t%s" %(ip,result))
			socket.close()
		except Exception ,e:
			print("Error Ip:%s" %(ip)),
			print(e)
		ip = client.lpop("ip")
